﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace dpdw.CompoundPattern
{
    /// <summary>
    /// 观察者的主题
    /// </summary>
    public class Observable : IQuackObservable
    {
        ArrayList observers = new ArrayList();
        IQuackObservable duck;

        public Observable(IQuackObservable duck)
        {
            this.duck = duck;
        }

        public void RegisterObserver(Observer observer)
        {
            observers.Add(observer);
        }

        public void NotifyObservers()
        {
            foreach (Observer observer in observers)
            {
                observer.Update(duck);
            }
        }
    }
}
